import wx
from wx import aui

from core.model import TestModel, Model
from roadview import RoadView, ConnectorView
from roadcanvas import RoadCanvas

ID_OPENNET=wx.NewId()
ID_OPENFLOW=wx.NewId()
ID_EXIT=wx.NewId()

ID_VIEW_PREF=wx.NewId()

ID_PROPAGATE=wx.NewId()

ID_PAN=wx.NewId()
ID_ZOOM=wx.NewId()
ID_CHOOSE=wx.NewId()

class MainFrame(wx.Frame):
	def __init__(self):
		wx.Frame.__init__(self, None)

		#self._mgr=aui.AuiManager()
		#self._mgr.SetManagedWindow(self)
		self.make_menubar()
		#self.make_toolbar()
		#self.make_statubar()

		shapefiles = [r"D:\myproject\dynat\ljz\ljz_node.shp",
			r"D:\myproject\dynat\ljz\ljz_link.shp",
			r"D:\myproject\dynat\ljz\ljz_zone_centroid.shp",
			r"D:\myproject\dynat\ljz\ljz_connector.shp"]
		self.model = Model(shapefiles)

		view1 = RoadView(self.model)
		self.canvas = RoadCanvas(self, view1)
		view2 = ConnectorView(self.model)
		self.canvas.SetModel(view2)
		self.timer = wx.Timer(self)
		self.Bind(wx.EVT_TIMER, self.OnTimer)
		#self._mgr.Update()
		self.timer.Start(100)

	def OnTimer(self, evt):
		self.model.update()
		self.Refresh(False)
	
	def make_menubar(self):
		mb=wx.MenuBar()
		#file menu
		file_menu=wx.Menu()
		file_menu.Append(ID_OPENNET,"Open Net")
		file_menu.Append(ID_OPENFLOW,"Open Flow")
		file_menu.Append(ID_EXIT,"Exit")
		mb.Append(file_menu,"File")
		#self.Bind(wx.EVT_MENU,self.OnOpenNet,id=ID_OPENNET)
		#self.Bind(wx.EVT_MENU,self.OnInitModel,id=ID_OPENFLOW)
		#self.Bind(wx.EVT_MENU,self.OnExit,id=ID_EXIT)
		
		#view menu
		view_menu=wx.Menu()
		view_menu.Append(ID_VIEW_PREF,"Preference")
		mb.Append(view_menu,"View")
		#self.Bind(wx.EVT_MENU,self.OnViewPref,id=ID_VIEW_PREF)

		#Procedure
		proc_menu=wx.Menu()
		proc_menu.Append(ID_PROPAGATE,"Propagate")
		mb.Append(proc_menu,"Procedure")

		#self.Bind(wx.EVT_MENU,self.OnPropagate,id=ID_PROPAGATE)
		
		self.SetMenuBar(mb)

	def make_toolbar(self):
		#navigation toolbar
		pan_img=wx.Image("pan.jpeg").ConvertToBitmap()
		zoom_img=wx.Image("zoom.jpeg").ConvertToBitmap()
		choose_img=wx.Image("choose.jpeg").ConvertToBitmap()
		tb1=wx.ToolBar(self,-1,style=wx.TB_VERTICAL|
				wx.TB_NODIVIDER)#|wx.TB_FLAT)
		tb1.SetToolBitmapSize(wx.Size(48,48))
		
		tb1.AddRadioLabelTool(ID_PAN,"Pan",pan_img)
		tb1.AddRadioLabelTool(ID_ZOOM,"Zoom",zoom_img)
		tb1.AddRadioLabelTool(ID_CHOOSE,"Choose",choose_img)
		tb1.AddSeparator()
		tb1.Realize()

		self._mgr.AddPane(tb1,aui.AuiPaneInfo().Name("tb1").
				Caption("Basic Navigation").ToolbarPane().
				Left().GripperTop().TopDockable(False).
				BottomDockable(False))

		#self.Bind(wx.EVT_MENU,self.OnNav,id=ID_PAN)
		#self.Bind(wx.EVT_MENU,self.OnNav,id=ID_ZOOM)
		#self.Bind(wx.EVT_MENU,self.OnNav,id=ID_CHOOSE)

		
		#file toolbar
		tb2=wx.ToolBar(self,-1,style=wx.TB_FLAT|wx.TB_NODIVIDER)
		tb2.SetToolBitmapSize(wx.Size(24,24))

		tb2.AddLabelTool(ID_OPENNET,"Open",wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN))
		#tb2.AddLabelTool(ID_CLOSEFILE,"Close",wx.ArtProvider_GetBitmap(wx.ART_DELETE))
		tb2.AddSeparator()
		#slider for timestep
		#self._timestep_slider=wx.Slider(tb2,-1,0,0,11,style=wx.SL_HORIZONTAL | wx.SL_AUTOTICKS)
		#self._timestep_slider.Disable()
		#ch=["Ref Flow","Estimated Flow","Discrepency"]
		#self._canvas_choice=wx.Choice(tb2,-1,choices=ch)
		#self._canvas_choice.Disable()
		#tb2.AddControl(self._timestep_slider)
		#tb2.AddControl(self._canvas_choice)
		
		tb2.Realize()
		self._mgr.AddPane(tb2,aui.AuiPaneInfo().Name("tb2").
				Caption("File").ToolbarPane().
				Top().LeftDockable(False).BottomDockable(False))
		
		#self.Bind(wx.EVT_SLIDER,self.OnView)
		#self.Bind(wx.EVT_CHOICE,self.OnView)
		

	def make_statubar(self):
		pass
		
if __name__ == "__main__":
	app = wx.App(False)
	frame = MainFrame()
	frame.Show()
	app.MainLoop()
